import React, { Component } from "react";
import { Text, View, StyleSheet, TouchableOpacity, Image, TextInput, PermissionsAndroid, Platform, DeviceEventEmitter, Switch } from 'react-native';
import Constant from '../../utils/Constant'//全局变量
import { getImgUrl } from '../../utils/ComFunction';
import HttpUtils from "../../utils/HttpUtils";
import HttpUrls from "../../utils/HttpUrls";
import Header from "../../components/header";
import { ToastToUser } from "../../utils/CustomToast";
import ActionSheet from 'react-native-actionsheet'
import ImageCropPicker from 'react-native-image-crop-picker';
import Upload from '../../components/upload/Upload'
import { requestCameraPermission, requestWritePermission } from '../../utils/Permission';
import Loading from "../../utils/Loading";
import AndroidModule from "../../utils/AndroidConnent";
import CommonDialog from "../../components/dialog/CommonDialog";
const isAndroid = Platform.OS == 'android';
import DeviceInfo from 'react-native-device-info';

export default class AboutShuaiche extends Component {

    constructor(props) {
        super(props);
        this.state = {
            isPushEnabled: true,
            dialogVisible: false,
            year: new Date().getFullYear(),
            versionText: '',
            focreUpdate: 0,
            description:'',
            downloadUrl:'' 
        };
    }

    componentDidMount() {
        this.getVersionInfo()
    }

    render() {
        const navigation = this.props.navigation;
        return (
            <View
                style={styles.container}>
                <Header navigation={navigation} Title={'关于帅车'} />                

                <Image style={styles.logoImg} source={require('source/image/comm/login_logo.png')}></Image>
                <Text style={styles.versionText}>V{DeviceInfo.getVersion()}</Text>

                <View
                    style={[styles.itemContain, { marginTop: 50 }]}>
                    <Text style={styles.titleText}>微信公众号</Text>
                    <Text style={styles.valueText}>shuaiche8</Text>
                </View>
                <View
                    style={styles.itemContain}>
                    <Text style={styles.titleText}>官方微博</Text>
                    <Text style={styles.valueText}>帅车官博</Text>
                </View>
                <View
                    style={styles.itemContain}>
                    <Text style={styles.titleText}>企业邮箱</Text>
                    <Text style={styles.valueText}>service@shuaiche.com</Text>
                </View>

                {isAndroid ?
                    <TouchableOpacity
                        style={styles.itemContain}
                        onPress={() => {

                            if(this.state.versionText == '有新版本'){
                                let obj = {
                                    type:this.state.focreUpdate,
                                    versionMsg: this.state.description,
                                    downloadUrl: this.state.downloadUrl
                                }
                                AndroidModule.updateDialog(obj)
                            }else{
                                ToastToUser('当前已是最新版本')
                            }
                            
                        }}>
                        <Text style={[styles.titleText, { flex: 1 }]}>检查更新</Text>


                        <Text style={{ fontSize: 14, color: '#ED542E' }}>{this.state.versionText}</Text>
                        <Image style={styles.arrowImg} source={require('source/image/comm/icon_tree_arrow.png')}></Image>

                    </TouchableOpacity>

                    : null
                }


                <View style={{ flex: 1 }}>

                </View>

                <Text>杭州帅车网络科技有限公司版权所有</Text>
                <Text style={{ marginBottom: 20 }}>Copright ©{this.state.year} Shuaiche.All Rights Reserved</Text>

            </View>
        );
    }

    getVersionInfo() {

        let params = {
            terminalType: isAndroid ? 14 :15
        }

        HttpUtils.getRequest(HttpUrls.getSysVersion, params)
            .then((result) => {
                let code = result.code
                if (code == 0) {
                    if(result.data){
                        let newversion = result.data.version.replaceAll('.', '')
                        let nowVersion = DeviceInfo.getVersion().replaceAll('.', '')
                        let version = newversion > nowVersion ? '有新版本' : '已是最新版本'
                        this.setState({
                            versionText: version,
                            focreUpdate: result.data.focreUpdate,
                            description:result.data.description,
                            downloadUrl:result.data.url
                        })
                    }else{
                        this.setState({
                            versionText: '已是最新版本'
                        })
                    
                        
                    }
                    
                }
            })
            .catch((error) => {

            });
    }

};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        flexDirection: 'column',
        alignItems: 'center'
    },


    logoImg: {
        width: 80,
        height: 80,
        marginTop: 40
    },
    versionText: {
        fontSize: 14,
        color: '#333333',
        marginTop: 5
    },
    itemContain: {
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'space-between',
        height: 50,
        borderBottomColor: '#e4e4e4',
        borderBottomWidth: 0.3,
        width: '100%',
        paddingLeft: 15,
        paddingRight: 15
    },
    titleText: {
        fontSize: 16,
        color: '#333333'
    },
    valueText: {
        fontSize: 16,
        color: '#999999'
    },
    arrow: {
        fontSize: 18,
        color: '#333333',
    },
    arrowImg: {
        width: 15,
        height: 15
    },


});